import {
  Controller,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  Get,
  Req,
} from '@nestjs/common';
import { UserService } from './user.service';
import { UpdateUserDto } from './dto/update-user.dto';
import { ApiOperation, ApiBody, ApiBearerAuth } from '@nestjs/swagger';
import { Auth } from 'src/common/decorators/auth.decorator';
// import { AuthGuard } from '@nestjs/passport';


@Auth()
@ApiBearerAuth()
@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  // @Post('add')
  // create(@Body() createUserDto: CreateUserDto) {
  //   return this.userService.create(createUserDto);
  // }

  @Post('addRole')
  @ApiOperation({ summary: '为用户添加角色' })
  @ApiBody({
    description: '用户ID和角色ID',
    type: 'object',
    schema: {
      type: 'object',
      properties: {
        userId: { type: 'number', description: '用户ID' },
        roleId: { type: 'number', description: '角色ID' },
      },
      required: ['userId', 'roleId'],
    },
  })
  addRole(@Body() body: { userId: number; roleId: number }) {
    return this.userService.addRole(body.userId, body.roleId);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
    return this.userService.update(+id, updateUserDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.userService.remove(+id);
  }

  @Get('checkLogin')
  checkLogin(@Req() req) {
    // return '登录成功';
    return req.user;
  }
}
